package  
{
	import org.flixel.FlxG;
	import org.flixel.FlxGroup;
	import org.flixel.FlxPoint;
	import org.flixel.FlxSprite;
	import Data.Color;
	import Data.Images;
	import org.flixel.FlxText;
	/**
	 * ...
	 * @author Chase Skinner
	 */
	public class Inventory extends FlxGroup
	{
		public var inventoryGroup:FlxGroup;
		
		private var clueSelection:FlxSprite;
		private var clueInfo:FlxText;
		private var itemCount:int = 0;
		private var clueIndex:int = 2;
		
		public function Inventory():void
		{
			super();
			createInventory();
		}
		
		public function createInventory():void
		{
			inventoryGroup = new FlxGroup();
			
			var image:FlxSprite = new FlxSprite(0, 0, Images.BAG);
			image.scrollFactor.x = 0;
			image.scrollFactor.y = 0;
			inventoryGroup.add(image);
			
			clueSelection = new FlxSprite(25, 70, Images.GLOW);
			clueSelection.scrollFactor.x = 0;
			clueSelection.scrollFactor.y = 0;
			clueSelection.scale = new FlxPoint(2, 2);
			clueSelection.visible = false;
			inventoryGroup.add(clueSelection);
			
			clueInfo = new FlxText(320, 0, 320);
			clueInfo.scrollFactor.x = 0;
			clueInfo.scrollFactor.y = 0;
			add(clueInfo);
			clueInfo.size = 20;
			clueInfo.visible = false;
			
			add(inventoryGroup);
		}
		
		override public function update():void
		{
			super.update();
		}
		
		public function addClue(clue:Clue):void
		{			
			if (inventoryGroup.length <= 5)
			{
				clue.y = 80;
			}
			else
			{
				clue.y = 160;
			}
			
			if (itemCount > 3)
			{
				itemCount = 0;
			}
			
			if (!clueSelection.visible)
			{
				clueSelection.visible = true;
			}
			
			clue.x = 80 * itemCount + 30;
			clue.scrollFactor.x = 0;
			clue.scrollFactor.y = 0;
			inventoryGroup.add(clue);
			itemCount++;
		}
		
		public function changeSelection():void
		{
			if (!clueSelection.visible)
			{
				return;
			}
			else 
			{
				clueInfo.visible = true;
			}
			
			if ((FlxG.keys.justPressed("RIGHT") || FlxG.keys.justPressed("D")) && clueSelection.x <= 200)
			{
				clueSelection.x += 78;
				clueIndex += 1;
			}
			else if ((FlxG.keys.justPressed("LEFT") || FlxG.keys.justPressed("A")) && clueSelection.x >= 30)
			{
				clueSelection.x -= 78;
				clueIndex -= 1;
			}
			else if ((FlxG.keys.justPressed("UP") || FlxG.keys.justPressed("W")) && clueSelection.y >= 80)
			{
				clueSelection.y -= 80;
				clueIndex -= 4;
			}
			else if ((FlxG.keys.justPressed("DOWN") || FlxG.keys.justPressed("S")) && clueSelection.y <= 150)
			{
				clueSelection.y += 81;
				clueIndex += 4;
			}
			
			clueInfo.text = GetClueInfo(inventoryGroup.members[clueIndex]);
		}
		
		private function GetClueInfo(clue:Clue):String
		{
			try
			{
				switch(clue.item)
				{
				case Images.BLOODY_FOOTPRINT:
					return "This is a bloody footprint";
					break;
				case Images.BOOK:
					return "This is a book";
					break;
				case Images.CANDLESTICK:
					return "This is a candle stick";
					break;
				case Images.CARPET_TUFT:
					return "This is a carpet tuft";
					break;
				case Images.CASSETTE_TAPE:
					return "This is a cassette tape";
					break;
				case Images.CIGARETTE_BUTT:
					return "This is a cigarette butt";
					break;
				case Images.CROSS:
					return "This is a cross";
					break;
				case Images.CYANIDE:
					return "This is a cyanide bottle";
					break;
				case Images.KNIFE:
					return "This is a knife";
					break;
				case Images.EARRINGS:
					return "These are earrings";
					break;
				case Images.FABRIC_SCRAP:
					return "This is a fabric scrap";
					break;
				case Images.FIBERWIRE:
					return "This is a fiber wire";
					break;
				case Images.GLASSES:
					return "These are glasses";
					break;
				case Images.HAIR_STRAND:
					return "This is a hair strand";
					break;
				case Images.HANDBAG:
					return "This is a handbag";
					break;
				case Images.KEY:
					return "This is a key";
					break;
				case Images.LIGHTER:
					return "This is a lighter";
					break;
				case Images.LIPSTICK:
					return "This is lipstick";
					break;
				case Images.MONOCLE:
					return "This is a monocle";
					break;
				case Images.MUDDY_FOOTPRINT:
					return "This is a muddy foot print";
					break;
				case Images.NECKLACE:
					return "This is a necklace";
					break;
				case Images.NOOOSE:
					return "This is a noose";
					break;
				case Images.NOTE:
					return "This is a note";
					break;
				case Images.NOTE_2:
					return "This is a note2";
					break;
				case Images.NOTE_3:
					return "This is a note3";
					break;
				case Images.NOTE_4:
					return "This is a note4";
					break;
				case Images.NOTE_5:
					return "This is a note5";
					break;
				case Images.GUN:
					return "This is a gun";
					break;
				case Images.PHOTOS:
					return "This is an envelope of photos";
					break;
				case Images.PIPE:
					return "This is a pipe";
					break;
				case Images.RING:
					return "This is a ring";
					break;
				case Images.SCARF:
					return "This is a scarf";
					break;
				case Images.TORN_PAPER:
					return "This is a torn piece of paper";
					break;
				default:
					return "No clue present";
					break;
				}
			}
			catch (e:Error)
			{
				return "No clue present";
			}
			
			return "Error";
		}
	}
}